/** @file Server.h 
*/
#include "stdafx.h"

#ifndef _Server_h_
#define _Server_h_

#include "MessageIdentifiers.h"
#include "RakPeerInterface.h"
	
#include "RakNetTypes.h"
#include "BitStream.h"
	
#include <string>
#include <iostream>
#include <vector>

#include "SpawnCommand.h"
#include "DisconnectCommand.h"
#include "SynchCommand.h"

/**
* @brief Clients are represented here as class with id and an address
*
* 
*/

class Clients {
	public:
	int id;
	RakNet::SystemAddress address;
	
	Clients::Clients(int identifier, RakNet::SystemAddress systemAddress) {
			id = identifier;
			address = systemAddress;
	};
};

/** @class Server
*   @brief The Server waiting is for network messages from clients and are ready to send out the information to all other clients
* 
*/

class Server {
	private:
		char* maxPlayers;
		char* serverPort;
		char* serverPassword;
		bool canSync;

		RakNet::Packet *packet;
		RakNet::MessageID type;
		RakNet::RakString rs;

		bool connected;
		Model *model;
	public:
		RakNet::RakPeerInterface *server;
		RakNet::BitStream bsOut;
		RakNet::SystemAddress server_address;

		/**
		* @brief The createServer creates and startup a server with the set port, password, maximum players.
		* 
		*/
		void createServer(char* port, char* password, char* maxNumPlayers, Model* model);
		/**
		* @brief recievePackets are waiting for network messages
		* 
		*/
		void receivePackets();
		/**
		* @brief shut downs the server
		* 
		*/
		void terminateServer();
		/**
		* @brief get information on how many are connected, and gives these addresses
		* 
		*/
		void serverInfo();
		/**
		* @brief spawn adds a new client to the server and sens out the information to everyone connected
		* 
		*/
		void spawn();
		/**
		* @brief command just pass the "command" (action) out to all other clients
		* 
		*/
		void command(RakNet::BitStream &bsIn);
		/**
		* @brief removes a client
		*
		*/
		void disconnectClient();
		std::list<Clients*> clientList;
};

#endif